/*
 * @(#)MaintUserDelegationForm.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.user.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.web.AbstractActionForm;
import com.dcivision.user.bean.UserDelegation;

/**
  MaintUserDelegationForm.java

  This class is the for web form purpose.

  @author      Rollo Chan
  @company     DCIVision Limited
  @creation date   16/03/2004
  @version     $Revision: 1.7 $
*/

public class MaintUserDelegationForm extends AbstractActionForm {

  public static final String REVISION = "$Revision: 1.7 $";

  private String sourceUserID = null;
  private String targetObjectType = GlobalConstant.SUBJECT_TYPE_USER;
  private String targetObjectID = null;
  private String startDate = null;
  private String endDate = null;
  private String delegationRule = null;
  private String objectType = GlobalConstant.OBJECT_TYPE_WORKFLOW;
  private String objectID = null;

  private String alertByEmail = null;
  private String alertBySystem = null;
  private String notificationType = null;

  public MaintUserDelegationForm() {
    super();
  }

  public String getSourceUserID() { 
    return(this.sourceUserID);
  }

  public void setSourceUserID(String sourceUserID) { 
    this.sourceUserID = sourceUserID;
  }

  public String getTargetObjectType() { 
    return(this.targetObjectType);
  }

  public void setTargetObjectType(String targetObjectType) { 
    this.targetObjectType = targetObjectType;
  }

  public String getTargetObjectID() { 
    return(this.targetObjectID);
  }

  public void setTargetObjectID(String targetObjectID) { 
    this.targetObjectID = targetObjectID;
  }

  public String getStartDate() { 
    return(this.startDate);
  }

  public void setStartDate(String startDate) { 
    this.startDate = startDate;
  }

  public String getEndDate() { 
    return(this.endDate);
  }

  public void setEndDate(String endDate) { 
    this.endDate = endDate;
  }

  public String getDelegationRule() { 
    return(this.delegationRule);
  }

  public void setDelegationRule(String delegationRule) { 
    this.delegationRule = delegationRule;
  }

  public String getObjectType() { 
    return(this.objectType);
  }

  public void setObjectType(String objectType) { 
    this.objectType = objectType;
  }

  public String getObjectID() { 
    return(this.objectID);
  }

  public void setObjectID(String objectID) { 
    this.objectID = objectID;
  }

  public String getAlertByEmail() {
    return (this.alertByEmail);
  }

  public void setAlertByEmail(String alertByEmail) {
   this.alertByEmail = alertByEmail;
  }

  public String getAlertBySystem() {
    return (this.alertBySystem);
  }

  public void setAlertBySystem(String alertBySystem) {
    this.alertBySystem = alertBySystem;
  }
  public String getNotificationType() {
      return (this.notificationType);
    }

    public void setNotificationType(String notificationType) {
      this.notificationType = notificationType;
    }


  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    return super.validate(mapping, request);
  }

  public void reset(ActionMapping mapping, HttpServletRequest request) {
    super.reset(mapping, request);
    this.setID(null);
    this.setSourceUserID(null);
    this.setTargetObjectType(GlobalConstant.SUBJECT_TYPE_USER);
    this.setTargetObjectID(null);
    this.setStartDate(null);
    this.setEndDate(null);
    this.setDelegationRule(null);
    this.setObjectType(GlobalConstant.OBJECT_TYPE_WORKFLOW);
    this.setObjectID(null);
    this.setNotificationType(null);
    this.setRecordStatus(null);
    this.setUpdateCount(null);
    this.setCreatorID(null);
    this.setCreateDate(null);
    this.setUpdaterID(null);
    this.setUpdateDate(null);

    this.setAlertByEmail(null);
    this.setAlertBySystem(null);
  }

  public AbstractBaseObject getFormData() throws ApplicationException {
    UserDelegation tmpUserDelegation = new UserDelegation();
    tmpUserDelegation.setID(TextUtility.parseIntegerObj(this.getID()));
    tmpUserDelegation.setSourceUserID(TextUtility.parseIntegerObj(this.getSourceUserID()));
    tmpUserDelegation.setTargetObjectType(this.getTargetObjectType());
    tmpUserDelegation.setTargetObjectID(TextUtility.parseIntegerObj(this.getTargetObjectID()));
    tmpUserDelegation.setStartDate(parseTimestamp(this.getStartDate()));
    tmpUserDelegation.setEndDate(parseTimestamp(this.getEndDate()));
    tmpUserDelegation.setDelegationRule(this.getDelegationRule());
    tmpUserDelegation.setObjectType(this.getObjectType());
    tmpUserDelegation.setObjectID(TextUtility.parseIntegerObj(this.getObjectID()));
    tmpUserDelegation.setNotificationType(this.getNotificationType());
    tmpUserDelegation.setRecordStatus(this.getRecordStatus());
    tmpUserDelegation.setUpdateCount(TextUtility.parseIntegerObj(this.getUpdateCount()));
    tmpUserDelegation.setCreatorID(TextUtility.parseIntegerObj(this.getCreatorID()));
    tmpUserDelegation.setCreateDate(parseTimestamp(this.getCreateDate()));
    tmpUserDelegation.setUpdaterID(TextUtility.parseIntegerObj(this.getUpdaterID()));
    tmpUserDelegation.setUpdateDate(parseTimestamp(this.getUpdateDate()));
    return tmpUserDelegation;
  }

  public void setFormData(AbstractBaseObject baseObj) throws ApplicationException {
    UserDelegation tmpUserDelegation = (UserDelegation)baseObj;
    this.setID(TextUtility.formatIntegerObj(tmpUserDelegation.getID()));
    this.setSourceUserID(TextUtility.formatIntegerObj(tmpUserDelegation.getSourceUserID()));
    this.setTargetObjectType(tmpUserDelegation.getTargetObjectType());
    this.setTargetObjectID(TextUtility.formatIntegerObj(tmpUserDelegation.getTargetObjectID()));
    this.setStartDate(formatTimestamp(tmpUserDelegation.getStartDate()));
    this.setEndDate(formatTimestamp(tmpUserDelegation.getEndDate()));
    this.setDelegationRule(tmpUserDelegation.getDelegationRule());
    this.setObjectType(tmpUserDelegation.getObjectType());
    this.setObjectID(TextUtility.formatIntegerObj(tmpUserDelegation.getObjectID()));
    this.setNotificationType(tmpUserDelegation.getNotificationType());
    this.setRecordStatus(tmpUserDelegation.getRecordStatus());
    this.setUpdateCount(TextUtility.formatIntegerObj(tmpUserDelegation.getUpdateCount()));
    this.setCreatorID(TextUtility.formatIntegerObj(tmpUserDelegation.getCreatorID()));
    this.setCreateDate(formatTimestamp(tmpUserDelegation.getCreateDate()));
    this.setUpdaterID(TextUtility.formatIntegerObj(tmpUserDelegation.getUpdaterID()));
    this.setUpdateDate(formatTimestamp(tmpUserDelegation.getUpdateDate()));
    if (notificationType!=null){
      if (notificationType.indexOf('E')!=-1){
          this.setAlertByEmail("E");
      }
      if (notificationType.indexOf('S')!=-1){
          this.setAlertBySystem("S");
      }
    }
  }
}
